# -*- coding: utf-8 -*-
'''
@author: Donny
@Created on: 2011-8-29
@version: 2011.8.29
@summary: unit test of Databasehandler class
'''
import unittest
from util.databasehandler import DatabaseHandler

class DatabaseHandler_Test(unittest.TestCase):
    '''
    DatabaseHandler method unit test.
    '''        
    def setUp(self):
        '''
        Set up test data.
        '''
        print 'databasehandler_test -- setUp '
        host = 'localhost'
        user = 'root'
        password = ''
        database = 'osim'
        self.db_handler = DatabaseHandler(host, user, password, database)
    
    def tearDown(self):
        '''
        Tear down test.
        '''
        print 'databasehandler_test -- tearDown '
        self.db_handler = None
        
    def test_insert(self):
        '''
        Test insert method.
        '''
        print 'databasehandler_test -- test_insert '
        table = 'osim_report'
        result_dict = {}
        result_dict["TimeStamp"] = '20110829_1510'
        result_dict["CaseId"] = '123456'
        result_dict["StepName"] = 'Step1'
        result_dict["StepDescription"] = 'Description'
        result_dict["ExpectedResult"] = 'ExpectedResult'
        result_dict["StepResult"] = 'Passed'
        result_dict["TestLog"] = 'test log information'#step.test_log
        result_dict["Screenshot"] = 'screenshot'
        if self.db_handler.insert(table, result_dict):
            print 'databasehandler_test -- test_insert: insert done! '
            
    def test_get(self):
        '''
        Test get method.
        '''
        print 'databasehandler_test -- test_get '
        table = 'osim_report'
        print self.db_handler.get(table)
        
    def test_set(self):
        '''
        Test set method.
        '''
        print 'databasehandler_test -- test_set '
        table = 'osim_report'
        setField = 'StepDescription'
        setValue = '"aaaaa"'
        whereField = 'CaseId' 
        whereValue = '"123456"'
        print self.db_handler.set(table, setField, setValue, 
                                  whereField, whereValue)
        
        
if __name__ == "__main__":
#    unittest.main()
    suite = unittest.TestSuite()
    suite.addTest(DatabaseHandler_Test("test_set"))
    unittest.TextTestRunner().run(suite)
